Repository navigation
feat(import): keep the diagram layout when re-importing a B-UML file (Refs #774) - #778
Merged
ArmenSl merged 3 commits intoNov 12, 2026
Conversation
/get-json-model takes an optional existing_model (the diagram the file updates). The imported Class, Agent or State Machine diagram is then laid out like it: matched elements keep their id, position and size, new ones are placed next to a neighbour, and warnings report what was kept, added and missing. The agent converter now reports the parts of a file it could not read (buml-import-partial) instead of only logging them. Refs #774
…t-json-model Refs #774
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #774. Backend first step (option A of the analysis): re-importing a B-UML
.pyfile can keep the layout of the diagram it updates. The editor part follows in a second PR.What changes
services/converters/layout_adoption.py(new):adopt_layout(existing, imported) -> (model, report)over the v4 wire shape (nodes/edges,positionrelative toparentId,data.pointson edges).components(intents with their bodies, LLMs, ...) keep their existing ids, matched by name inside their match. References to the remapped ids, such astargetMethodId, follow them.ShelftoRackis reported as removed and added.pointsis cleared and the editor routes the edge again.POST /besser_api/get-json-modeltakes an optional form fieldexisting_model. When it is present, the imported diagram goes throughadopt_existing_layout. Without it the response is the same as before. This also applies when the uploaded file is a project and the endpoint picks one diagram from it.agent_buml_to_json(content, warnings=None)now reports what it could not read: the whole-file fallback, plus bodies and statements it skipped./get-json-modelreturns these asbuml-import-partialwarnings. An agent written with keyword arguments (agent.new_intent(name=...)) used to import as an empty diagram with HTTP 200 and no warning. It still imports empty, but the response now says why.DiagramExportResponse.warnings([{code, message, ...}]) already existed. The new codes add structured keys.Diagram types covered
/get-json-model, a state-machine.pyis still detected as an agent (.new_state(is an agent marker; that is finding 2 of the analysis and out of scope here). With anexisting_modelof typeStateMachineDiagram, the endpoint answerslayout-not-adopted("the existing diagram is a StateMachineDiagram, the file holds a AgentDiagram") and does not adopt the layout silently.existing_modelis ignored with alayout-not-adoptedwarning. BPMN, Component and Deployment diagrams already keep their layout through B-UML./get-project-json-model: not changed. It builds a new project throughproject_to_json, which is a different code path.Warning codes
layout-adoptedexisting_modelwas usedmatched,edgesKept,edgesRerouted,edgesAddedelement-renamedelementId,type,from,nameelement-addedelementId,type,name,placedNextTo(name or null)element-not-in-importelementId,type,namelayout-not-adoptedexisting_modelnot JSON, not v4 (nodes), another diagram type, or a type without adoptionbuml-import-partialTests
tests/.../services/converters/test_layout_adoption.py(11 tests): unchanged agent and unchanged class keep every node, edge, row and component id and position; a new state is placed next to its neighbour without overlap; a rename with the same connections keeps its place; an isolated rename is reported as removed and added; a removed state is reported; same-named nodes are paired in order and no id is used twice; an edge drops its bend points when an end grew; a state machine round trip keeps its layout; an unusableexisting_model(invalid JSON, v3, another type, unsupported type) is ignored with a warning; an empty existing diagram leaves the imported layout as it is.tests/.../backend/test_layout_preserving_import.py(4 endpoint tests, using the backend'sclientfixture): end-to-end re-import withexisting_model; noexisting_modelgives the old response; invalidexisting_modelgives a warning; a keyword-style agent givesbuml-import-partial.Commands, run serially in a venv with
pip install -e .[dev], the backend requirements and.[django](pytest-xdist collected different test ids per worker here, so I did not use-n auto):The three failures are unrelated to this change:
test_secret_redaction_callers.py::test_the_agent_transform_endpoint_logs_its_config_redactedposts a v3 agent model, which this branch rejects with HTTP 400 before the log line it checks. This PR does not touch that endpoint.test_derived_enum_entity_can_be_createdfailures come from the local host: bubblewrap cannot create namespaces there ("the shell sandbox is unavailable on this server").The docs build (
docs/check_docs.py) could not run in my sandbox, becausesphinx_immaterialstarts a multiprocessing manager. The edited RST section parses cleanly with docutils..github/scripts/check_openapi.pywill probably report the editor's committed OpenAPI schema as stale: the endpoint gained a form field and its docstring changed. The editor PR has to regenerate the schema (see below).Editor follow-up
What the React Flow editor (BESSER-Web-Modeling-Editor) has to do in a second PR:
features/import/useImportDiagram.ts, which adds a new tab), add "Update current diagram from file (.py)". The current behaviour stays the default.POST /besser_api/get-json-model, multipart, withbuml_file(the.pyfile, as today) andexisting_model, set toJSON.stringify(currentDiagram.model). That is the v4 model of the diagram being updated, withtype,nodes,edgesand, for agents,components. A{ model: ... }project-diagram entry is accepted too. Sendexisting_modelonly for this action and only when the current diagram is aClassDiagram,AgentDiagramorStateMachineDiagram. For the plain "import as new tab" action, do not send it. Starlette caps a form text field at 1 MB: an agent whosecomponents[*].guiModelis large can be sent withoutguiModel, since only ids, types, names, positions, sizes, rows, components and edges are read.DiagramExportResponse. Replace the current diagram'smodelwithresponse.modelin place, keeping the diagram id, title and envelope (config,references). Matched elements already carry their old ids, so cross-diagram references and the GitHub three-way merge keep working.response.warnings. Showelement-added(withplacedNextTo),element-renamedandelement-not-in-import: the update deletes what the file no longer has, so the user confirms first. Showlayout-not-adopted(the diagram would get a new layout) andbuml-import-partial(content was not read) as warnings. Unknown codes keep going to the existing toast path (reportImportRepairs.ts).npm run api:generateinpackages/webappand commitopenapi/besser-openapi.json, then bump the submodule pointer here. Add the new warning codes toshared/api/conversion.ts.projects.rst, on what "update from file" does with a diagram of the same identity. Also i18n strings for the action and the report.Other follow-ups that were not done here: state-machine detection in
/get-json-model(finding 2), the agent re-import content differences (finding 3), andbuml-import-partialon the project import path.Handover
adopt_layout/adopt_existing_layoutinservices/converters/layout_adoption.py; the router change is inget_single_json_model.ClassLinkReledge, which is anchored on another edge, is matched by its ends, so it gets a new id when its target edge was remapped. Only new top-level nodes are placed; new child nodes keep the position the converter gave them inside their parent.